package com.qxy.practice.concurrent;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author : 戚欣扬
 * @Description :
 */
public class AutoIntegerDemo {

    public static void main(String[] args) {
        AtomicInteger autoInteger = new AtomicInteger(666);
        //定义一个标准CPU密集型设计线程池
        ExecutorService threadPoolExecutor = new ThreadPoolExecutor(
                Runtime.getRuntime().availableProcessors(),
                Runtime.getRuntime().availableProcessors()+1,
                1L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(6),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        System.out.println("I have "+Runtime.getRuntime().availableProcessors()+" processors");
        try {
            for (int i = 0; i < 5; i++) {
                threadPoolExecutor.execute(()->{
                    for (int j = 0; j < 20; j++) {
                        System.out.println(Thread.currentThread().getName()+" AInteger : "+autoInteger.incrementAndGet());
                    }
                });
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            threadPoolExecutor.shutdown();
        }

    }
}


